<template>
  <el-container>
    <div class="header">
      <div class="title">苏小课后台管理系统</div>
      <div class="user-info">
        <div class="notification">
          <i class="bell-icon">🔔</i>
          <span class="badge">1</span>
        </div>
        <div class="user">您好，管理员！</div>
        <div class="actions">
          <a href="./login.html">退出</a>
        </div>
      </div>
    </div>
    <el-header>
      <div class="breadcrumb-nav">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item @click='navigateTo("adminHome/home.html")'>首页</el-breadcrumb-item>
          <el-breadcrumb-item>消息发送</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </el-header>

    <el-main>
      <div class="content-wrapper">
        <el-form :model="message" label-width="80px">
          <el-form-item label="标题">
            <el-input v-model="message.title"></el-input>
          </el-form-item>
          <el-form-item label="内容">
            <el-input v-model="message.content" type="textarea"></el-input>
          </el-form-item>
          <el-form-item label="发送至">
            <el-select v-model="message.recipient" placeholder="请选择">
              <el-option label="教师" value="teacher"></el-option>
              <el-option label="学生" value="student"></el-option>
              <el-option label="全体用户" value="system"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="sendMessage">发送</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref } from 'vue';
import axios from 'axios';

const message = ref({
  title: '',
  content: '',
  sender: '管理员',
  recipient: '',
  time: new Date().toLocaleDateString(),
});

const sendMessage = () => {
  axios.post('http://localhost:9090/sendMessage', message.value)
    .then(response => {
      console.log("消息发送成功", response);
      // 可在此添加成功后提示
      location.reload();
    })
    .catch(error => {
      console.log("消息发送失败", error);
      // 可在此添加失败后提示
    });
};

const navigateTo = (page) => {
  window.location.href = `/src/pages/${page}`;
};
</script>

<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: #fff;
  border-bottom: 1px solid #ddd;
}

.header .title {
  font-size: 24px;
  color: #1e90ff;
}

.header .user-info {
  display: flex;
  align-items: center;
}

.header .user-info .notification {
  margin-right: 20px;
  position: relative;
}

.header .user-info .notification .badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: red;
  color: #fff;
  border-radius: 50%;
  padding: 2px 5px;
  font-size: 12px;
}

.header .user-info .user {
  margin-right: 10px;
  color: #333;
}

.header .user-info .actions a {
  margin: 0 5px;
  color: #1e90ff;
  text-decoration: none;
}

.el-header {
  background-color: #fff;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.breadcrumb-nav {
  padding: 0 20px;
}

.content-wrapper {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
